//
//  WBHomeViewController.swift
//  Weibo
//
//  Created by 夏灵烽 on 2025/1/1.
//

import UIKit

private let cellId = "cellId"

class WBHomeViewController: WBBaseViewController {

    private lazy var statusList = [String]()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    // MARK: - 重写 设置 界面
    
    override func setupTableView() {
        super.setupTableView()
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "好友", target: self, action: #selector(showFriends))
        
        tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellId)
    }

    @objc func showFriends() {
        let vc = WBTestViewController()
        navigationController?.pushViewController(vc, animated: true)
    }
    
    // MARK: - 重写 加载数据
    
    override func loadData() {
        DispatchQueue.main.asyncAfter(deadline: .now() + 5.0, execute: {
            
            for i in 0..<20 {
                if self.isPullup == true {
                    self.statusList.append("shangla \(i)")
                } else {
                    self.statusList.insert(i.description, at: 0)
                }
                
            }
            
            self.isPullup = false
            
            self.refreshControl?.endRefreshing()
            self.tableView?.reloadData()
        })
        
        
    }
    
    // MARK: - 重写 tableView 数据源方法

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return statusList.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath)
        cell.textLabel?.text = statusList[indexPath.row]
        return cell
    }
    
}



